#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int countTexts(string pressedKeys) {
        int n = pressedKeys.size(), mod = 1e9 + 7, prev = 1;
        vector<vector<int>> dp(n, vector<int>(5));
        dp[0][1] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i][1] = prev;
            if (pressedKeys[i] != pressedKeys[i - 1]) continue;
            int num;
            if (pressedKeys[i] == '7' || pressedKeys[i] == '9') num = 4;
            else num = 3;
            for (int j = 1; j < num; j++) {
                if (dp[i - 1][j] == 0) break;
                dp[i][j + 1] = dp[i - 1][j];
                prev = (prev + dp[i][j + 1]) % mod;
            }
        }
        // for(int i = 0; i < n; i++){
        //     for(int j = 1; j < 5; j++) cout << dp[i][j] << ' ';
        //     cout << endl;
        // }
        return prev;
    }
};